home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Using a Pen to Draw Lines and Shapes / Joining Lines / GDITEST27.dpr
Encoding:
Text File  |  2003-10-15  |  2.5 KB  |  103 lines

  1. program GDITEST27;
  2.  
  3. uses
  4.   Windows,
  5.   Messages,
  6.   SysUtils,
  7.   GDIPAPI,
  8.   GDIPOBJ;
  9.  
  10. Procedure OnPaint(DC: HDC);
  11. var
  12.   graphics : TGPGraphics;
  13.   pen: TGPPen;
  14.   path: TGPGraphicsPath;
  15.   p1, p2, p3: TGPPoint;
  16. begin
  17.   graphics := TGPGraphics.Create(DC);
  18.   pen:= TGPPen.Create(MakeColor(255, 0, 0, 255),8);
  19.   path:= TGPGraphicsPath.Create;
  20.  
  21.   path.StartFigure;
  22.   p1.X := 50;  p1.Y := 200;
  23.   p2.X := 100; p2.Y := 200;
  24.   p3.X := 100; p3.Y := 250;
  25.  
  26.   path.AddLine(p1, p2);
  27.   path.AddLine(p2, p3);
  28.  
  29.   pen.SetLineJoin(LineJoinRound);
  30.   graphics.DrawPath(pen, path);
  31.  
  32.   path.Free;
  33.   pen.Free;
  34.   graphics.Free;
  35. end;
  36.  
  37.  
  38. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  39. var
  40.   Handle: HDC;
  41.   ps: PAINTSTRUCT;
  42. begin
  43.   case message of
  44.     WM_PAINT:
  45.       begin
  46.         Handle := BeginPaint(Wnd, ps);
  47.         OnPaint(Handle);
  48.         EndPaint(Wnd, ps);
  49.         result := 0;
  50.       end;
  51.  
  52.     WM_DESTROY:
  53.       begin
  54.         PostQuitMessage(0);
  55.         result := 0;
  56.       end;
  57.  
  58.    else
  59.       result := DefWindowProc(Wnd, message, wParam, lParam);
  60.    end;
  61. end;
  62.  
  63. var
  64.   hWnd     : THandle;
  65.   Msg      : TMsg;
  66.   wndClass : TWndClass;
  67. begin
  68.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  69.    wndClass.lpfnWndProc    := @WndProc;
  70.    wndClass.cbClsExtra     := 0;
  71.    wndClass.cbWndExtra     := 0;
  72.    wndClass.hInstance      := hInstance;
  73.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  74.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  75.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  76.    wndClass.lpszMenuName   := nil;
  77.    wndClass.lpszClassName  := 'GettingStarted';
  78.  
  79.    RegisterClass(wndClass);
  80.  
  81.    hWnd := CreateWindow(
  82.       'GettingStarted',       // window class name
  83.       'Joining Lines',      // window caption
  84.       WS_OVERLAPPEDWINDOW,    // window style
  85.       Integer(CW_USEDEFAULT), // initial x position
  86.       Integer(CW_USEDEFAULT), // initial y position
  87.       Integer(CW_USEDEFAULT), // initial x size
  88.       Integer(CW_USEDEFAULT), // initial y size
  89.       0,                      // parent window handle
  90.       0,                      // window menu handle
  91.       hInstance,              // program instance handle
  92.       nil);                   // creation parameters
  93.  
  94.    ShowWindow(hWnd, SW_SHOW);
  95.    UpdateWindow(hWnd);
  96.  
  97.    while(GetMessage(msg, 0, 0, 0)) do
  98.    begin
  99.       TranslateMessage(msg);
  100.       DispatchMessage(msg);
  101.    end;
  102. end.
  103.